<template>
  <div class="main">
    <basic-layout title="物资退还" :showAddBtn="false" :showFilterBtn="false"
                  @handleFilter="$refs.queryPopupRef.show = true">
      <div class="dataStyle">
        <van-cell-group>
          <van-cell title="设备名称" :border="false" :value="dataInfo.pinm">
          </van-cell>
          <van-cell title="实物编码" :border="false" :value="dataInfo.swid">
          </van-cell>

          <van-cell title="设备型号" :border="false" :value="dataInfo.xingh">
          </van-cell>
          <van-cell title="生产厂家" :border="false" :value="dataInfo.sccj">
          </van-cell>
          <van-cell title="设备大类" :border="false" :value="dataInfo.dal">
          </van-cell>
          <van-cell title="设备小类" :border="false" :value="dataInfo.xiaol">
          </van-cell>
          <van-cell title="所属楼宇" :border="false" :value="dataInfo.fangcname">
          </van-cell>
          <van-cell title="保管人" :border="false" :value="dataInfo.baogr">
          </van-cell>
          <van-cell title="退还仓库" v-model="dataInfo.changk ||'选择仓库' " is-link @click="showDialogHandle()"/>
          <van-action-sheet
            v-model="show"
            cancel-text="取消"
            :actions="data.defaultData.ckDataList"
            @select="onSelect"
          />
        </van-cell-group>
        <div class="buttonMainStyle">
          <van-button type="primary" size="large" color="#4eb3e9" @click="saveHandle">保存</van-button>
        </div>
      </div>

    </basic-layout>
  </div>
</template>
<script>

import {
  getDetailBySwid, queryCk, tuih
} from '@/api/srvAssurance/assetLabel/assetLabel'

export default {
  components: {},
  data () {
    return {
      show: false,
      dataInfo: {
        id: '',
        pinm: '',
        xingh: '',
        swid: '',
        dal: '',
        xiaol: '',
        zhuangt: '',
        shebType: '',
        baogr:'',
        changk: ''
      },
      data: {
        defaultData: {
          ckDataList: [], //大类数据
        }
      },
      queryParam: {
        fangjmc: null,
        pageIndex: 1,
        pageSize: 10,
      },
    }
  },

  created () {
    this.saomiaozc()
    this.initLbType()
  },
  methods: {

    async saomiaozc () {
      this.loading = true
      let _this = this
      wx.scanQRCode({
        desc: 'scanQRCode desc',
        needResult: 1, // 默认为0，扫描结果由i国网处理，1则直接返回扫描结果，
        scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
        success: async function (res) {
          if (res.resultStr) {
            let queryParam = {}
            queryParam.swid = res.resultStr
            let resData = await getDetailBySwid(queryParam)
            if (resData.status == 0) {
              for (const key in resData.data) {
                _this.dataInfo = resData.data[key]
              }
            }
          }
        },
        error: function (res) {
          if (res.errMsg.indexOf('function_not_exist') > 0) {
            alert('版本过低请升级')
          }
        }
      })
      this.loading = false
    },
    async initLbType () {
      this.queryParam.fangjmc = sessionStorage.getItem('corpId')
      let lbDatas = await queryCk(this.queryParam)
      this.data.defaultData.ckDataList = lbDatas.data.map(item => {
        return {
          'name': item.NAME,
          'LYID': item.LYID,
          'loucid': item.LCID,
          'fangjid': item.ID,
        }
      })
    },

    onSelect (item) {
      this.dataInfo.changk = item.name
      this.queryParam.louyid = item.LYID
      this.queryParam.loucid = item.loucid
      this.queryParam.fangjid = item.fangjid
      this.show = false
    },
    async showDialogHandle () {
      this.show = true
    },
    async saveHandle () {
      if (this.dataInfo.changk == '' || this.dataInfo.changk == null) {
        this.$toast('请先选择仓库')
        return
      }
      this.queryParam.type = this.dataInfo.shebType
      this.queryParam.shebid = this.dataInfo.id
      let res = await tuih(this.queryParam);
      if (res.status == 0) {
        this.$toast(res.message);
      } else {
        this.$toast('退还失败')
      }
    }
  }
}
</script>

<style scoped lang="less">
.main {
  .dataStyle {
    height: calc(100% - 1px);
    overflow: auto;

    .van-cell {
      width: 93%;
      border-bottom: 1px solid #eee;
      margin: 0 auto;
    }
  }

  .van-cell__title {
    margin-left: -10px;
  }

  .buttonMainStyle {
    display: flex;
    justify-content: space-around;
    bottom: 30px;
    left: 0;
    width: 100%;
    margin-top: 33px;

    .vanButtonStyle {
      border-radius: 10px;
      width: 85%;
      display: flex;
      justify-content: space-around;
      border: none;
      font-size: 20px;
    }
  }


}

.van-button--large {
  height: 40px;
  line-height: 40px;
  width: 95%;
  margin: 10px auto;
}

/deep/ .van-hairline--top:after {
  border: 1px solid #00000029;
}


</style>
